package cn.yshujia.controller;

import cn.yshujia.domain.dto.PageDTO;
import cn.yshujia.domain.entity.Develop;
import cn.yshujia.domain.vo.ApiVO;
import cn.yshujia.domain.vo.PageVO;
import cn.yshujia.service.impl.DevelopServiceImpl;
import com.alibaba.fastjson2.JSON;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author YShuJia
 * @since 2024/4/23
 */
@RestController
@Tag (name = "Develop", description = "开发Api")
public class DevelopController {
	
	@Resource
	private DevelopServiceImpl service;
	
	@GetMapping ("/develop/page")
	@Operation (summary = "获取所有开发信息")
	public ApiVO<PageVO<Develop>> pageByBranch(@RequestParam String dto) {
		PageDTO pageDTO = JSON.parseObject(dto, PageDTO.class);
		
		if (null == pageDTO) {
			return ApiVO.error();
		}
		return ApiVO.success(service.pageByBranch(pageDTO));
	}
	
	@PostMapping ("/admin/develop/insert")
	@Operation (summary = "从Gitee更新开发信息")
	public ApiVO<Boolean> insert(@RequestParam String branch) {
		return ApiVO.success(service.insert(branch));
	}
}
